<template>
  <div>
    <!-- <svg>
      <use xlink:href="#icon-fullscreen" />
    </svg> -->
    <!-- 全屏按钮 -->
    <svg-icon v-if="isFull" icon-class="exit-fullscreen" class="fullscreen" @click="toggleFullScreen" />
    <svg-icon v-else icon-class="fullscreen" class="fullscreen" @click="toggleFullScreen" />
  </div>
</template>

<script>
import ScreenFull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFull: false// 记录当前全屏状态
    }
  },
  // ScreenFull.isEnabled 判断全屏是否能用
  // ScreenFull.toggle 全屏/退出全屏
  methods: {
    toggleFullScreen() {
      // 全屏
      if (ScreenFull.isEnabled) {
        // 能用
        ScreenFull.toggle()
        this.isFull = !this.isFull
      } else {
        // 不能用
        this.$message.error('很遗憾 您不能全屏 请更新')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  fill: #fff;
  cursor: pointer;
}
</style>
